package com.ebt.m.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

/**
 * 状态管理 修改/获取键值对的值
 * 
 * @author Michael.li
 * 
 */
public class StateManager {
	private static StateManager _instance;
	private static SharedPreferences mSettings;

	private StateManager() {
	}

	public static StateManager getInstance(Context context) {
		if (_instance == null) {
			_instance = new StateManager();
			mSettings = PreferenceManager.getDefaultSharedPreferences(context);
			if (!mSettings.contains(WIKI_CORPFOLDER_VISIBLE)) {
				mSettings.edit().putBoolean(WIKI_CORPFOLDER_VISIBLE, true).commit();
			}
		}
		return _instance;
	}

	/** 首次安装 */
	public static final String FIRSTINSTALL_KEY = "FIRSTINSTALL_KEY";

	/** 数据同步时间 */
	public static final String DATA_SYNC = "data_sync";
	/** 公司推荐数据同步时间 */
	public static final String DATA_SYNC_FOR_COMPANY = "data_sync_4_company";
	/** 帐号 */
	public static final String ACCOUNT = "account";
	/** 帐号ID */
	public static final String ACCOUNT_ID = "account_id";
	/** 自动登录 */
	public static final String ACCOUNT_AUTOSIGN = "account_autosign";
	/** 自动登录开始日期 */
	public static final String ACCOUNT_AUTOSIGN_START_DATE = "account_autosign_start_date";
	/** 自动登录保留天数 */
	public static final String ACCOUNT_DAY = "account_day";

	/** 险种百科-浏览记录是否显示 */
	public static final String WIKI_VISIBLE_HISTORY = "wiki_visible_history";
	/** 险种百科-公司列表大图显示 */
	public static final String WIKI_LOGO = "wiki_logo";
	/** 险种百科-数据同步时间 */
	public static final String WIKI_DATA_SYNC_TIME = "wiki_data_sync_time";

	/** 公司推荐-是否显示 */
	public static final String WIKI_CORPFOLDER_VISIBLE = "wiki_corpfolder_visible";
	/** 公司推荐-是否已同步 */
	public static final String WIKI_CORPFOLDER_SYNC = "wiki_corpfolder_sync";
	/** 公司推荐-同步时间 */
	public static final String WIKI_CORPFOLDER_SYNC_TIME = "wiki_corpfolder_sync_time";
	/** 公司推荐-自动同步公司文件夹 */
	public static final String WIKI_CORPFOLDER_AUTO_SYNC = "auto_folder";
	/** 合作公司自动检查默认值 */
	public static final boolean WIKI_CORPFOLDER_AUTO_SYNC_DEFAULT_VALUE = true;

	/** 我的公司-是否有上架产品更新 */
	public static final String SETTING_MYCOMPANY_HAS_NEW = "mycompany_has_new";
	/** 我的公司-第一次登录时初始化是否注册公司的状态 */
	public static final String INIT_REGISTERED_CORP = "INIT_REGISTERED_CORP";

	/** 代理公司名称 */
	public static final String WIKI_AGENT_COMPANY_NAME = "wiki_agent_company_name";

	/** 险种百科-利益说明自动人工语音 */
	public static final String WIKI_VOICE_AUTO_PLAY = "wiki_voice_auto_play";
	/** 险种百科-自动检查更新 */
	public static final String WIKI_AUTO_CHECK_UPDATE = "wiki_auto_check_update";
	/** 险种百科-是否有产品更新 */
	public static final String WIKI_HAS_PRODUCT_UPDATE = "wiki_has_product_update";
	/** 险种百科-计划书在售产品开关 */
	public static final String WIKI_RECOMMENDED_PRODUCT_SWITCH = "wiki_recommended_product_switch";
	/** 险种百科-计划书在售产品选择 |分割 */
	public static final String WIKI_RECOMMENDED_PRODUCT_TYPE_ID = "wiki_recommended_product_type_id";
	/** 险种百科-计划书在售产品选择、分割 */
	public static final String WIKI_RECOMMENDED_PRODUCT_TYPE_Name = "wiki_recommended_product_type_Name";
	/** 险种百科-仅显示投保规则产品 */
	public static final String WIKI_SHOW_RULE_PRODUCT = "wiki_show_rule_product";
	/** 险种百科-仅显示最后更新的产品 */
	public static final String WIKI_SHOW_LAST_PRODUCT = "wiki_show_last_product";
	/** 险种百科-是否显示销售渠道图标 */
	public static final String WIKI_SHOW_CHANNEL_ICON = "wiki_show_channel_icon";
	/** 险种百科-是否显示表格中的小数 */
	public static final String WIKI_SHOW_FLOAT = "wiki_show_float";
	/** 险种百科-是否显示表格中的小数 */
	public static final String WIKI_REGISTER_TIP = "wiki_register_tip";

	/** 险种百科-是否显示表格中的小数 */
	public static final String WIKI_SHOW_CORP_WITHPRODUCT = "wiki_show_corp_withProduct";
	/** 仅显示最后更新的产品 */
	public static final String WIKI_LAST_UPDATED_PRODUCT = "WIKI_LAST_UPDATED_PRODUCT";

	/** 客户关系-是否显示客户分类 */
	public static final String CUSTOMER_SHOW_CATEGORY = "CUSTOMER_SHOW_CATEGORY";
	/** 客户关系-添加客户是默认性别 */
	public static final String CUSTOMER_DEFAULT_SEX = "CUSTOMER_DEFAULT_SEX";
	/** 客户关系-添加客户是默认职业类别ID */
	public static final String CUSTOMER_DEFAULT_CAREER_TYPE_ID = "CUSTOMER_DEFAULT_CAREER_TYPE_ID";
	/** 客户关系-添加客户是默认职业类别Name */
	public static final String CUSTOMER_DEFAULT_CAREER_TYPE_NAME = "CUSTOMER_DEFAULT_CAREER_TYPE_NAME";
	/** 客户关系-添加客户是默认年龄 */
	public static final String CUSTOMER_DEFAULT_AGE = "CUSTOMER_DEFAULT_AGE";

	/** 我的行程-周日还是周一开始 */
	public static final String CALENDAR_START_DAY = "CALENDAR_START_DAY";

	/** 消息列表-是否提示 */
	public static final String MESSAGE_ALERT = "MESSAGE_ALERT";

	/** 消息列表-是否提示默认值 */
	public static final boolean MESSAGE_ALERT_DEFAULT_VALUE = true;
	/** 消息列表-密钥到期提醒天数 */
	public static final String MESSAGE_ALERT_DAYS = "MESSAGE_ALERT_DAYS";
	/** 消息列表-代理公司消息 */
	public static final String MESSAGE_RIGISTER_COMPANY = "message_register_company";
	/** 消息列表-代理公司消息默认值 */
	public static final boolean MESSAGE_RIGISTER_COMPANY_DEFAULT_VALUE = true;
	/** 消息列表-宜保云消息 */
	public static final String MESSAGE_CLOUD = "message_cloud";
	/** 消息列表-自动删除旧消息 */
	public static final String MESSAGE_AUTO_DELETE = "message_auto_delete";
	/** 消息列表-旧消息总数 */
	public static final String MESSAGE_INDEX_MAX_COUNT = "message_index_max_count";
	/** 消息列表-旧消息总数默认值 */
	public static final int MESSAGE_INDEX_DEFAULT_MAX_COUNT = 50;

	/** 消息列表-消息同步频率 */
	public static final String MESSAGE_UPDATE_INTERVAL_MINUTE = "MESSAGE_UPDATE_INTERVAL_MINUTE";
	/** 消息列表-消息同步频率 */
	public static final int MESSAGE_UPDATE_DEFAULT_INTERVAL_MINUTE = 10;

	/** 消息列表-显示期间 */
	public static final String MESSAGE_SET_INTERVAL_DAYS = "MESSAGE_SET_INTERVAL_DAYS";

	/** 数据安全与同步-仅使用wifi */
	public static final String DATA_SYNC_WIFI_ONLY = "data_sync_wifi_only";
	/** 数据安全与同步-密码安全开关 */
	public static final String DATA_SYNC_SECURITY_PWD = "data_sync_security_pwd";
	/** 数据安全与同步-密码安全 */
	public static final String DATA_SECURITY_PWD = "data_security_pwd";
	/** 数据安全与同步-备份时间 */
	public static final String DATA_SYNC_SECURITY_BACKUPTIME = "data_sync_security_backuptime";
	/** 数据安全与同步-恢复时间 */
	public static final String DATA_SYNC_SECURITY_RESETTIME = "data_sync_security_resettime";

	/** 展业夹-默认本地路径 */
	public static final String FOLDER_DEFAULT_PATH = "folder_default_path";

	/**
	 * 客户云计划书-推送手机和电子邮件
	 */
	public static final String CUSTOMER_CLOUD_SENDTO = "customer_cloud_sendto_";
	/** 客户云计划书-推送手机和电子邮件 */
	public static final String CUSTOMER_CLOUD_SEND_PHONE = "customer_cloud_send_phone_";
	/** 客户云计划书-推送手机和电子邮件 */
	public static final String CUSTOMER_CLOUD_SEND_EMAIL = "customer_cloud_send_email_";
	/** 客户云计划书-模板客户称谓 */
	public static final String CUSTOMER_CLOUD_CALL = "customer_cloud_call_";
	/** 客户云计划书-模板产品推荐 */
	public static final String CUSTOMER_CLOUD_PRODUCT_RECOMMEND = "customer_cloud_product_recommend_";
	/** 客户云计划书-模板组合类型 */
	public static final String CUSTOMER_CLOUD_COMBINE_TYPE = "customer_cloud_combine_type_";
	/** 客户云计划书-有效期间 */
	public static final String CUSTOMER_CLOUD_VALIDITY_DAYS = "customer_cloud_validity_days_";
	/** 客户云计划书-计划书附言模板 */
	public static final String CUSTOMER_CLOUD_PLAN_POSTSCRIPT = "customer_cloud_plan_postscript_";

	/** 关于宜保通-版本更新 */
	public static final String SETTING_ABOUT_AUTO_CHECK_APK = "setting_about_check_apk";
	/** 关于宜保通-有版本更新 */
	public static final String SETTING_ABOUT_NEW_HAS_APK = "setting_about_new_has_apk";
	/** 关于宜保通-版本更新url */
	public static final String SETTING_ABOUT_NEW_APK_URL = "setting_about_new_apk_url";
	/** apk立即检查时间 */
	public static final String SETTING_ABOUT_APK_CHECK_TIME = "setting_about_apk_check_time";
	/** apk更新内容 */
	public static final String SETTING_ABOUT_NEW_APK_UPDATE_CONTENT = "setting_about_apk_update_content";

	/** 共享文件信息 */
	public static final String SHAREDPREFERENCES_USERINFO = "USER_INFO";
	public static final String SHAREDPREFERENCES_USERID = "USER_ID";
	public static final String SHAREDPREFERENCES_USERNAME = "USER_NAME";
	public static final String SHAREDPREFERENCES_PASSWORD = "PASSWORD";
	/** 帐号-绑定设备 */
	public static final String ACCOUNT_BIND_DEVICE_PHONE = "account_bind_device_phone";
	/** 帐号-绑定设备 */
	public static final String ACCOUNT_BIND_DEVICE_EMAIL = "account_bind_device_email";

	/** 笔颜色CheckedId */
	public static final String PENCIL_COLOR = "pencil_color";
	/** 笔态CheckedId */
	public static final String PENCIL_STATE = "pencil_state";
	/** 笔透明度CheckedId */
	public static final String PENCIL_TRANS = "pencil_trans";
	/** 笔尺寸 */
	public static final String PENCIL_SIZE = "pencil_size";

	/** 桌面花盆当前选中的第几个值 */
	public static final String DESKTOP_POTTING_NUM = "dektop_potting_num";

	/** 桌面相册选择类型（图片，视频） */
	public static final String DESKTOP_PHOTO_TYPE = "dektop_photo_type";
	/** 桌面相册视频文件路径 */
	public static final String DESKTOP_PHOTO_VIDEO_PATH = "dektop_photo_VIDEO";

	/** 我的行程事件提醒天数 **/
	public static final String CALENDAR_ALERT_DAYS = "calendar_alert_days";

	/** 用户密钥设备同步时间 **/
	public static final String USER_DEVICE_KEY_SYNC_TIME = "user_device_key_sync_time";

	/** 本地计划书夹与服务器同步时间 **/
	public static final String PROPOSAL_FOLDER_LOCAL_DELET_SYNC_TIME = "local_proposal_folder_sync_time";
	/** 本地计划书夹与服务器同步成功时间 **/
	public static final String LOCAL_PROPOSAL_FOLDER_LOCAL_DELET_SYNC_SUCCESS_TIME = "local_proposal_folder_sync_success_time";

	/** 点击相册的时候是否显示提示框 **/
	public static final String DESKTOP_CLICK_PHOTO_IS_SHOW_HELPER = "desktop_is_show_photo_alert";
	/** 点击公司图标的时候是否显示提示框 **/
	public static final String DESKTOP_CLICK_COMPANY_IS_SHOW_HELPER = "desktop_is_show_company_alert";
	/** 进入桌面时的时候是否显示提示框 **/
	public static final String DESKTOP_IS_SHOW_NOTE_ALERT = "desktop_is_show_note_alert";

	/** 修正博客消息时间(因为有发布错误的信息，需要清除数据，重新下载) **/
	public static final String MESSAGE_BLOG_NEED_REGET_DATA = "blog_msg_reget_flag";

	/** 不再提示设备不符合条件 */
	public static final String NO_LONGER_ALERT_DEVICE = "NO_LONGER_ALERT_DEVICE";

	/** 提示设置名片 */
	public static final String ALERT_SET_BUSINESS_CARD = "ALERT_SET_BUSINESS_CARD";
	/** 是否已同步名片 */
	public static final String ALREADY_SYSNC_BUSINESS_CARD = "ALREADY_SYNC_BUSINESS_CARD";
	/** 不再提示确认名称 */
	public static final String CONFIRM_PROPOSAL_NAME = "CONFIRM_PROPOSAL_NAME";

	/** 20151026-公司头像 */
	public static final String CARD_COMPANY_PIC = "CARD_COMPANY_PIC";
	/** 注册手机号 */
	public static final String ACCOUNT_REGISTER_PHONE = "ACCOUNT_REGISTER_PHONE";
	/** 注册手机号的上次验证码 */
	public static final String ACCOUNT_REGISTER_LAST_CHECK_CODE = "ACCOUNT_REGISTER_LAST_CHECK_CODE";
	/** 注册手机号的上次验证码发送时间 */
	public static final String ACCOUNT_REGISTER_CHECK_CODELAST_SEND_TIME = "ACCOUNT_REGISTER_CHECK_CODELAST_SEND_TIME";

	// 移动端新加
	//WIKI_CHOOSED_COMPANY_ID-已选择的公司
	public static final String WIKI_CHOOSED_COMPANY_ID = "WIKI_CHOOSED_COMPANY_ID";

	//客户同步时间
	public static final String CUSTOMER_SYNC_TIME = "CUSTOMER_SYNC_TIME";

	//快捷登录时上次发送验证码的时间
	public static final String LOGIN_VALIDATECODE_TIME = "login_validatecode_time";

	/**
	 * 如果不存在则返回null
	 * 
	 * @param key
	 * @return
	 */
	public String getString(String key) {
		return mSettings.getString(key, null);
	}

	public String getString(String key, String value) {
		return mSettings.getString(key, value);
	}

	public void setString(String key, String value) {
		mSettings.edit().putString(key, value).commit();
	}

	/**
	 * 如果不存在则返回false
	 * 
	 * @param key
	 * @return
	 */
	public boolean getBoolean(String key) {
		return mSettings.getBoolean(key, false);
	}

	public boolean getBoolean(String key, boolean value) {
		return mSettings.getBoolean(key, value);
	}

	public void setBoolean(String key, boolean value) {
		mSettings.edit().putBoolean(key, value).commit();
	}

	/**
	 * 如果不存在则返回0
	 * 
	 * @param key
	 * @return
	 */
	public int getInt(String key) {
		return mSettings.getInt(key, 0);
	}

	/**
	 * 如果不存在则返回defaultValue
	 * 
	 * @param key
	 * @return
	 */
	public int getInt(String key, int defaultValue) {
		return mSettings.getInt(key, defaultValue);
	}

	public void setInt(String key, int value) {
		mSettings.edit().putInt(key, value).commit();
	}

	/**
	 * 删除变量值
	 * 
	 * @param key
	 */
	public void removeValue(String key) {
		mSettings.edit().remove(key).commit();
	}

	/**
	 * 删除变量值
	 * 
	 * @param key
	 */
	public void clearValue() {
		mSettings.edit().clear().commit();
	}

	/**
	 * 如果不存在则返回0
	 * 
	 * @param key
	 * @return
	 */
	public long getLong(String key) {
		return mSettings.getLong(key, 0);
	}

	/**
	 * 如果不存在则返回0
	 * 
	 * @param key
	 * @return
	 */
	public long getLong(String key, long dafault) {
		return mSettings.getLong(key, dafault);
	}

	/**
	 * 
	 * @Description: TODO
	 * @param key
	 * @param value
	 * @return boolean 是否保存成功
	 * @throw
	 */
	public boolean setLong(String key, long value) {
		return mSettings.edit().putLong(key, value).commit();
	}

	/* 公司注册-最新在线时间 */
	public static final String AGENT_COMPANY_NEW_ONLINE_TIME = "agent_company_new_online_time";
	/* 最大离线时间 */
	public static final String MAX_OFFLINE_INTERVAL_TIME = "max_offline_interval_time";
}
